package taskman.ui;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;

// import taskman.User;
import taskman.Interface4;
import taskman.ui.tablemodel.NonEditableDefaultTableModel;
import taskman.xml.XmlHelper;

public class Interface4ManagementWindow extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel contentPane;
	private JScrollPane scrollPane;
	private JTable table;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Interface4ManagementWindow frame = new Interface4ManagementWindow();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Interface4ManagementWindow() {
		setTitle("Interface4 Management");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(100, 100, 600, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		
		JLabel lblInterface4Table = new JLabel("Interface4 Table");
		contentPane.add(lblInterface4Table, BorderLayout.NORTH);
		
		scrollPane = new JScrollPane();
		contentPane.add(scrollPane, BorderLayout.CENTER);
		
		//Creating the table
		table = new JTable();
		DefaultTableModel model = new NonEditableDefaultTableModel();

		//Adding the Header to each column that needs to be displayed.
		model.addColumn("Name");
		model.addColumn("Hours assigned");
		model.addColumn("Task list");
		model.addColumn("ID");
		model.addColumn("Manager");
		model.addColumn("Started");

		//Getting all the interface4's info from the XmlHelper, inorder to put them in the table
		for(Interface4 w : XmlHelper.loadAllInterface4()) {
			model.addRow(new Object[]{w.getName(),w.getHours(),w.getTasks(), w.getId(), w.getmanager(), w.getstarted()});
		}
		table.setModel(model);
		table.getColumnModel().getColumn(0).setResizable(false);
		table.getColumnModel().getColumn(1).setResizable(false);
		table.getColumnModel().getColumn(2).setResizable(false);
		table.getColumnModel().getColumn(3).setResizable(false);
		table.getColumnModel().getColumn(4).setResizable(false);
		table.getColumnModel().getColumn(5).setResizable(false);
		
		
		scrollPane.setViewportView(table);
	}

}
